﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Manager;
using Model;
using ExtAspNet;
using Manager.CustomerHelper;
namespace HealthSystem
{
    public partial class CityAdmin_Edit : BasePage
    {
        HW_Manger_Admin_UserManager manager = new HW_Manger_Admin_UserManager();
        public override ModuleType Module
        {
            get
            {
                return ModuleType.CityAdmin;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnClose.OnClientClick = ActiveWindow.GetConfirmHidePostBackReference();
                string id = Request["id"].ToString();
                HW_Manger_Admin_User adminUser = manager.GetById(id);
                //bool exist = DistrictCache.CheckExist(CustomerProfile.DistrictId, school.DistrictCode);
                //if (exist)
                //{
                Bind(adminUser);
                //}
            }
        }
        public void Bind(HW_Manger_Admin_User adminUser)
        {
            this.name.Text = adminUser.hW_District.Name;
            this.id.Text = adminUser.XX_UserName;
            this.Address.Text = adminUser.hW_Admin_Detail.WorkUnit;
            this.Email.Text = adminUser.hW_Admin_Detail.Email;
            this.MobilePhone.Text = adminUser.hW_Admin_Detail.MobilePhone;
            OfficePhone.Text = adminUser.hW_Admin_Detail.OfficePhone;
            this.LinkMan.Text = adminUser.CNName;
            this.zipcode.Text = adminUser.hW_Admin_Detail.ZipCode;
            //Fax.Text = org.hw_OrgDetail.Fax;
        }
        protected void Save_Click(object sender, EventArgs e)
        {
            string id = Request["id"].ToString();
            HW_Admin_DetailManager detailManager = new HW_Admin_DetailManager();
            HW_Manger_Admin_User org = manager.GetById(id);
            bool exist = DistrictCache.CheckExist(CustomerProfile.DistrictId, org.DistrictCode);
            if (exist)
            {
                org.CNName = this.LinkMan.Text;
                //org.XX_UserName=
                //org.hW_Admin_Detail.Address = Address.Text;
                org.hW_Admin_Detail.Email = Email.Text; 
                org.hW_Admin_Detail.ZipCode = zipcode.Text;
                org.hW_Admin_Detail.WorkUnit = Address.Text;
                //org.hW_Admin_Detail.Fax = Fax.Text;
                //org.hW_Admin_Detail. = LinkMan.Text;
                org.hW_Admin_Detail.MobilePhone = MobilePhone.Text;
                org.hW_Admin_Detail.OfficePhone = OfficePhone.Text;
                manager.ModHW_Manger_Admin_User(org);
                detailManager.ModHW_Admin_Detail(org.hW_Admin_Detail);
                PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            }
            else
            {
                Alert.Show("您没有权限修改该学校");
            }
        }
    }
}